/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-4-17
 */
package controller;

import java.util.ResourceBundle;

public class CrawlerConfig {
	private String propertiesName;
	private ResourceBundle bundle;
	public CrawlerConfig(String propertiestName){
		this.propertiesName = propertiestName;
		bundle = ResourceBundle.getBundle(propertiestName);
	}
	public String getPropertiesName() {
		return propertiesName;
	}
	private String getValue(String key) {
		return bundle.getString(key).trim();
	}
	public String getGoogleKeywordListFilename() {
		return getValue("google.keywordlist.filename");
	}
	public String getGoogleKeywordCrawledListFilename() {
		return getValue("google.keywordcrawledlist.filename");
	}
	public int getGoogleResultCount() {
		int count = 50;
		try{
			count = Integer.parseInt(getValue("google.result.count"));
		}catch (Exception e) {
			count = 50;
		}
		return count;
	}
	public String getGoogleResultSavepath() {
		return getValue("google.result.savepath");
	}
	public int getGoogleWaitSecondMax(){
		int max = 100;
		try{
			max = Integer.parseInt(getValue("google.waitsecond.max"));
			if (max < 0){
				max = 50;
			}
		}catch (Exception e) {
			max = 100;
		}
		return max;
	}
	public int getGoogleWaitSecondMin(){
		int min = 50;
		try{
			min = Integer.parseInt(getValue("google.waitsecond.min"));
			if (min < 0){
				min = 50;
			}
		}catch (Exception e) {
			min = 50;
		}
		return min;
	}
	public int getTrainingCrawlThreadNum(){
		int thread_num = 10;
		try{
			thread_num = Integer.parseInt(getValue("training.crawl.threadnum"));
			if (thread_num <= 0){
				thread_num = 10;
			}
		}catch (Exception e) {
			thread_num = 10;
		}
		return thread_num;
	}
	public String getTrainingKeywordCrawledListFilename() {
		return getValue("training.keywordcrawledlist.filename");
	}
	public String getTrainingLinkCrawledListFilename() {
		return getValue("training.linkcrawledlist.filename");
	}
	public String getGoogleLinklistFilename() {
		return getValue("google.linklist.filename");
	}
	public String getGoogleBDBDirname() {
		return getValue("google.bdb.dirname");
	}
	public String getGoogleBDBDatabasename() {
		return getValue("google.bdb.databasename");
	}
	public String getTrainingOriginalSavepath(){
		return getValue("training.original.savepath");
	}
	public String getTrainingSegmentSavepath(){
		return getValue("training.segment.savepath");
	}
	public String getAPIBDBDirname() {
		return getValue("api.bdb.dirname");
	}
	public String getRefPageBDBDirname() {
		return getValue("ref.bdb.dirname");
	}
	public String getRefPageBDBDatabasename() {
		return getValue("ref.bdb.databasename");
	}
	public String getCodeExtractErrorFilename(){
		return getValue("code.extract.error.filename");
	}
	public String getDatabaseURL(){
		return getValue("api.example.database.url");
	}
	public String getDatabaseUsername(){
		return getValue("api.example.database.username");
	}
	public String getDatabasePwd(){
		return getValue("api.example.database.pwd");
	}
	public int getCodeExtractMaxseg(){
		int max = 5000;
		try{
			max = Integer.parseInt(getValue("code.extract.maxseg"));
			if (max <= 0){
				max = 5000;
			}
		}catch (Exception e) {
			max = 10;
		}
		return max;
	}
	public int getCodeExtractMinseg(){
		int min = 1;
		try{
			min = Integer.parseInt(getValue("code.extract.minseg"));
			if (min <= 0){
				min = 5000;
			}
		}catch (Exception e) {
			min = 10;
		}
		return min;
	}
	public int getBacklinkCrawlerThread(){
		int thread_num = 50;
		try{
			thread_num = Integer.parseInt(getValue("backlink.crawler.thread"));
			if (thread_num <= 0){
				thread_num = 50;
			}
		}catch (Exception e) {
			thread_num = 50;
		}
		return thread_num;
	}
	public int extractStateWaitSecond(){
		int wait_second = 50;
		try{
			wait_second = Integer.parseInt(getValue("code.extract.waitsecond"));
			if (wait_second <= 0){
				wait_second = 50;
			}
		}catch (Exception e) {
			wait_second = 50;
		}
		return wait_second;
	}
}
